package com.ostrich.cloud.ostrichBusinessWeb.app.Api;

import cn.hutool.core.bean.BeanUtil;
import com.ostrich.cloud.common.result.Result;
import com.ostrich.cloud.ostrichBusinessWeb.app.component.WebSocketServer;
import com.ostrich.cloud.ostrichBusinessWeb.client.DelivervWebClient;
import com.ostrich.cloud.ostrichBusinessWeb.client.param.PutDeliveryParam;
import com.ostrich.cloud.ostrichBusinessWeb.service.DelivervService;
import com.ostrich.cloud.ostrichBusinessWeb.service.param.StartDeliveryParam;
import com.ostrich.cloud.ostrichDistributionService.client.DeliveryOrderClient;
import com.ostrich.cloud.ostrichUserService.client.RiderMangerClient;
import com.ostrich.cloud.param.DeliveryOrderparam;
import com.ostrich.ostrichUserService.param.rider.RegRider;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class DeliveryWebApiImp implements DelivervWebClient {


    @Resource
    private DelivervService delivervService;
    @Resource
    private DeliveryOrderClient deliveryOrderClient;

    @Resource
    private RiderMangerClient riderMangerClient;

    @Override
    public Result startDelivery(PutDeliveryParam param) {
        StartDeliveryParam startDeliveryParam = BeanUtil.copyProperties(param, StartDeliveryParam.class);

        Result result = delivervService.startDelivery(startDeliveryParam);

        DeliveryOrderparam one = deliveryOrderClient.getOne(param.getDeliveryId());
        WebSocketServer.sendInfo(one,param.getRiderId()+"");
        return result;
    }

    @Override
    public Result riderRegister(RegRider regRider) {

        Result result = riderMangerClient.riderRegister(regRider);

        return result;
    }
}
